/*
 * Written by Rossi Kamal
 * Date 2011.01.06
 * 
 */

package net.m2m.policycompiler.smartdevice.smartphone.interpretation;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Smartphone3GInterpreter {

	
	public Smartphone3GInterpreter() {

		  try {
		  
		  File file = new File("/home/Siddiqui/workspace/M2M/policy_xml/smartdevice/smartphone/3g/Smartphone3GPolicy.xml");
		  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		  DocumentBuilder db = dbf.newDocumentBuilder();
		  Document doc = db.parse(file);
		  doc.getDocumentElement().normalize();
		  System.out.println("Root element " + doc.getDocumentElement().getNodeName());
		  
		  NodeList nodeLst = doc.getElementsByTagName("smartphone3g");
		  System.out.println("Policy for Smartphone 3G Service");

		  for (int s = 0; s < nodeLst.getLength(); s++) {

		    Node fstNode = nodeLst.item(s);
		    
		    if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
		  
		      Element fstElmnt = (Element) fstNode;
		      NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("m2mservice");
		      Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
		      NodeList fstNm = fstNmElmnt.getChildNodes();
		      System.out.println("M2M Service : "  + ((Node) fstNm.item(0)).getNodeValue());
		     
		      NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("bandwidth");
		      Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
		      NodeList lstNm = lstNmElmnt.getChildNodes();
		      System.out.println("M2M Bandwidth : " + ((Node) lstNm.item(0)).getNodeValue());
		    
		       
		    
		    }

		  }
		  } catch (Exception e) {
		    e.printStackTrace();
		  }
		 }
	
	public static void main(String args[]){
		Smartphone3GInterpreter s3G=new Smartphone3GInterpreter();
		
	}
}